package com.sanzang.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * 全局异常捕获
 * @author sanzang
 *
 */
@ControllerAdvice
public class SysExceptionHandler {
	
	@ExceptionHandler(value =Exception.class )
	public Object errorHandler(HttpServletRequest request,HttpServletResponse response,Exception ex) {
		ex.printStackTrace();
		//带数据跳转
		ModelAndView mv =new ModelAndView();
		mv.addObject("url",request.getRequestURI());
		mv.addObject("msg", ex.getMessage());
		mv.setViewName("error");
		return mv;
	}

}
